package marchsoft.modules.selfFish.finance.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import marchsoft.modules.selfFish.finance.service.CostService;
import marchsoft.response.Result;
import marchsoft.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**费用管理
 * @title CostController
 * @description 费用管理
 * @author Lenovo
 * @version 1.0
 * @create 2024-07-15 16:52
 */
@Slf4j
@RestController
@RequestMapping("/api/cost")
@Api(tags = "财务管理：费用管理")
public class CostController {

    @Autowired
    private CostService costService;
    @GetMapping
    @ApiOperation("获取费用列表")
    @PreAuthorize("@smpe.check('cost:list')")
    public Result<Object> query(String zhName,
                                @RequestParam(value ="pageNum",defaultValue = "1")Long pageNum,
                                @RequestParam(value ="pageSize",defaultValue = "10") Long pageSize ){
        log.info(StrUtil.format("【获取费用列表 /api/fish】操作人id：{}，费用查询条件 fishName：{}，分页pageNum：{}", SecurityUtils.getCurrentUserId(),zhName, pageNum));
        return costService.getCostList(zhName,pageNum,pageSize);
    }

    @GetMapping("/total")
    @ApiOperation("获取费用列表")
    @PreAuthorize("@smpe.check('cost:list')")
    public Result<Object> queryTotal(){
        return costService.getCostTotal();
    }

    @ApiOperation("导出鱼群数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@smpe.check('cost:list')")
    public void download(HttpServletResponse response, String zhName) throws IOException {
        log.info(StrUtil.format("【查询费用列表/api/download】操作人id：{}，费用列表查询条件 fishName：{}", SecurityUtils.getCurrentUserId(), zhName));
        costService.download(zhName,response);
    }

}
